<template>
  <van-nav-bar
    v-if="title"
    :title="title"
    left-arrow
    @click-left="router.back()"
  />
  <router-view></router-view>
  <TabBar v-if="showTabBar"></TabBar>
  <!-- 回到顶部 -->
  <van-back-top bottom="66" />
</template>

<script setup>
import { onMounted, ref, watch } from "vue";
import { RouterLink, RouterView, useRoute, useRouter } from "vue-router";
import useUserInfo from "@/stores/useUserInfo";
import { getToken } from "./utils/token";
import useCartInfo from "./stores/useCartInfo";

let showTabBar = ref(true);
let title = ref("");

let router = useRouter();
let route = useRoute();
let store = useUserInfo();
let storeCart = useCartInfo();

let onClickLeft = () => {};

watch(route, (newRoute) => {
  showTabBar.value = newRoute.meta.isShowNav;
  title.value = newRoute.meta.title;
});

// 刷新页面 重新查询个人信息存到仓库
onMounted(() => {
  // 调用用户信息接口 拿数据放到仓库
  // 本地有token信息---调用仓库action 内部调用直接存到仓库
  if (getToken()) {
    // 获取用户信息
    store.getUserInfo();
    // 获取购物车信息
    storeCart.getCartInfo();
  }
});
</script>

<style scoped>
</style>
